Release 10.1A: OpenEdge Application Server:
Developing WebSpeed Applications
Understanding the scope of database transactions
How does WebSpeed know where to start the database transaction and how much work to undo or back out? The following transaction blocks start a database transaction if one is not already active:
- Any block that uses the
TRANSACTIONkeyword on the block statement (DO,FOR EACH, orREPEAT).- A procedure block, trigger block, and each iteration of a
DOON ERROR,FOREACH, orREPEATblock that directly updates the database or directly reads records withEXCLUSIVE-LOCK. You useEXCLUSIVE-LOCKto read records in multi-user applications.Directly updating the database means that the block contains at least one statement that can change the database.
CREATE,DELETE, andUPDATEare examples of such statements.If a block contains
FINDorFOR EACHstatements that specifyEXCLUSIVE-LOCK, and at least one of theFINDorFOR EACHstatements is not embedded within inner transaction blocks, then the block is directly reading records withEXCLUSIVE-LOCK.Note that
DOblocks do not automatically have the transaction property. Also, if the procedure or database transaction you are looking at is run by another procedure, you must check the calling procedure to determine whether it starts a database transaction before theRUNstatement.Once a database transaction is started, all database changes are part of that transaction, until it ends. Each user of the database can have just one active transaction at a time. The procedure in Figure 8–4 has two blocks: the procedure block and the
REPEATblock.Figure 8–4: Database transaction scope
![]()
The procedure block has no statements directly in it that are not contained within the
REPEATblock. TheREPEATblock contains aCREATEstatement that lets you add order records to the database. Because theREPEATblock is the outermost block that contains direct updates to the database, it is the transaction block.At the start of an iteration of the
REPEATblock, WebSpeed starts a database transaction. If any errors occur before theENDstatement, WebSpeed backs out any work done during that transaction.Note that data-handling statements that cause WebSpeed to automatically start a database transaction for a regular table will not cause WebSpeed to automatically start a transaction for a work table or temporary table.
Figure 8–5 shows a procedure with multiple transactions.
Figure 8–5: Multiple DB transactions in a procedure Note: This example uses the
![]()
GetFieldmethod procedure where WebSpeed usage recommends theget-field()API function. See the online AppBuilder Help for more information.This procedure has four blocks:
- Procedure block — There are no statements in this block, so WebSpeed does not start a database transaction at the start of the procedure.
- Outer
REPEATblock — The outermost block that directly updates the database (CREATEorderWITH2COLUMNS). Therefore, it is a transaction block. On each iteration of this block, WebSpeed starts a database transaction. If an error occurs before the end of the block, all work done in that iteration is undone.- Inner
REPEATblock — Directly updates the database but it is not the outermost block to do so. Therefore, it is not a transaction block. It is, however, a subtransaction block. Subtransactions are discussed later in this chapter.FOR EACHblock — An outermost block that directly updates the database (UPDATEregion). Therefore, it is a transaction block. On each iteration of this block, WebSpeed starts a database transaction. If an error occurs before the end of the block, all work done in that iteration is undone.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |